<?php

class Quanly extends CI_Controller {

    //put your code here
    function __construct() {
        parent::__construct();
        $this->load->helper(array('form', 'url'));
        $this->load->model('m_sanpham');
        $this->load->model("m_categories");
        $this->load->model("m_units");
        $this->load->model("m_vendors");
    }
function home(){
    $this->load->view('index');
}
function product(){
    $this->load->view('product');
}
function index() {
        
        $data['category'] = $this->m_categories->gettulevel();// cai nay ha?
        $data['vendor'] = $this->m_vendors->getallvendors();
        $data['unit'] = $this->m_units->getallunits();
        $this->load->view('category', $data);
    }
    function loadsanpham(){
            $this->load->model("Msanpham");
            $data=$this->Msanpham->listsanpham();
            echo "<pre>";
            print_r($data);
            echo "</pre>";
        }
    function insert_data(){
            $config['upload_path'] = './uploads/images/';
            $config['allowed_types'] = 'gif|jpg|png';
            $config['max_size'] = '2000';
            $config['max_width'] = '13660';
            $config['max_height'] = '7680';
            $this->load->library('upload', $config);
            if (!$this->upload->do_upload()) {
                $error = array('error' => $this->upload->display_errors());
                var_dump($error);
            //$data['msg'] = "Lỗi";                
//            $this->load->vieng w('info_error', $error);
            } else {
            $upload_data = $this->upload->data();
            var_dump($upload_data);
            //$HinhAnh = 'uploads/images/' . $upload_data['file_name'];
            $thumb_image='uploads/images/' . $upload_data['file_name'];
            $full_image='uploads/images/' . $upload_data['file_name'];
            $data = array(
                'product_id'=>$this->input->post('product_id'),
                'unit_id' =>  $this->m_units->getunitid($this->input->post('unit_name')),
                'category_id'=>  $this->m_categories->getcategoryid($this->input->post('title')),
                'vendor_id'=> $this->m_vendors->getvendorid($this->input->post('company_name')),
                'product_sku'=> $this->input->post('product_sku'),
                'product_quantity'=>$this->input->post('product_quantity'),
                'product_date_added'=>$this->input->post('product_date_added'),
                'date_modify'=>$this->input->post('date_modify'),
                'product_publish'=>$this->input->post('product_publish'),
                'product_url'=>$this->input->post('product_url'),
                'product_price'=>$this->input->post('product_price'),
                'price_now'=>$this->input->post('price_now'),
                'product_weight'=>$this->input->post('product_weight'),
                'product_thumb_image'=>$thumb_image,
                'product_name_image'=>  $this->input->post('name_image'),
                'product_full_image'=>$full_image,
                'product_name'=>$this->input->post('product_name'),
                'short_description'=>nl2br(trim($this->input->post('short_description'))),
                'description'=>nl2br(trim($this->input->post('description'))),
            );
            var_dump($data);
             $this->m_sanpham->insertProduct($data);
                $data['msg'] = "Đã Thêm Hoa";
             $this->load->view('themsanpham', $data);
           
            }
        
         }
         function productdetail(){
             $this->load->view('product_top');
         }

}

?>
